package org.erp.procurement.controller;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.erp.common.domain.Result;
import org.erp.common.page.DataPageResp;
import org.erp.common.page.PageQueryModel;
import org.erp.procurement.convert.OrderProductDetailsConvert;
import org.erp.procurement.entity.bo.OrderProductDetailsQueryBo;
import org.erp.procurement.entity.bo.OrderProductDetailsUnPushStockBo;
import org.erp.procurement.entity.bo.OrderProductDetailsUpdateBo;
import org.erp.procurement.entity.vo.OrderProductDetailsVo;
import org.erp.procurement.service.OrderProductDetailsService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static org.erp.common.domain.Result.success;

/**
 * 订单产品详情控制层
 *
 * @author libin
 * @version 1.0
 * @description: 订单产品详情控制层
 * @date 2025/11/5 17:02
 **/
@Log4j2
@RestController
@AllArgsConstructor
@RequestMapping("/details")
public class OrderProductDetailsController {

    private final OrderProductDetailsService orderProductDetailsService;

    private final OrderProductDetailsConvert orderProductDetailsConvert;

    /**
     * 产品详情列表
     *
     * @param orderProductDetailsBo
     * @return
     */
    @PostMapping("/list")
    public Result<DataPageResp<OrderProductDetailsVo>> pageList(@RequestBody OrderProductDetailsQueryBo orderProductDetailsBo) {
        PageQueryModel<OrderProductDetailsVo> queryModel = orderProductDetailsService.pageList(orderProductDetailsConvert.boConvertDto(orderProductDetailsBo));
        return success(DataPageResp.of(queryModel.getTotal(), queryModel.getDataList()));
    }

    /**
     * 根据订单号查询订单详情
     *
     * @param orderNo
     * @return
     */
    @GetMapping("/findByOrderNo")
    public Result<List<OrderProductDetailsVo>> findByOrderNo(@RequestParam("orderNo") String orderNo) {
        return success(orderProductDetailsService.findByOrderNo(orderNo));
    }

    /**
     * 修改金额
     *
     * @param orderProductDetailsUpdateBo
     * @return
     */
    @PutMapping("/update")
    public Result<String> updateAmount(OrderProductDetailsUpdateBo orderProductDetailsUpdateBo) {
        orderProductDetailsService.updateAmount(orderProductDetailsUpdateBo);
        return success();
    }

    /**
     * 查询待入库手机列表
     * @param orderProductDetailsUnPushStockBo
     * @return
     */
    @PostMapping("/findUnPushStock")
    public Result<DataPageResp<OrderProductDetailsVo>> findUnPushStock(@RequestBody OrderProductDetailsUnPushStockBo orderProductDetailsUnPushStockBo) {
        PageQueryModel<OrderProductDetailsVo> queryModel = orderProductDetailsService.findUnPushStock(orderProductDetailsConvert.boConvertDto(orderProductDetailsUnPushStockBo));
        return success(DataPageResp.of(queryModel.getTotal(), queryModel.getDataList()));
    }
}
